<html>
<head>
<title>FaceMap</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAYgIFcdB73ikjsshF47qFhRT9MMXG_tYPVLibiAtjK-zmIeBb9RTQy57sFP4wbxEGLiuFm3mV7BVEKQ" type="text/javascript"></script>
<script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0" type="text/javascript"></script>

<script src="ClusterMarker.js" type="text/javascript"></script>
<script type="text/javascript">
	var points;
	var parser;
	var map;
	var myGMC;
	var marker;
	var marker_array=[];
	var exml;
	var mgr;
	var points;
	var coords;
	var descs;
	var EVENT_FEED_URL = "http://www.google.com/calendar/feeds/default/private/full";
	var AUTH_BUTTON = "auth-button";
	
	google.load("gdata", "1");
	function initialize() {
		if (GBrowserIsCompatible()) {
			/////////////////////////// load calendar
			google.load("gdata", "1");
			myCalendar = setupCalendarService();
			
			//Check Login status for both facebook and google


  			if (google.accounts.user.checkLogin(EVENT_FEED_URL)) {
				mystring = "<img src='facemapbanner_google.gif' usemap='#m_facemapbanner' border=0><map name='m_facemapbanner'><area shape='rect' coords='900,61,995,75' href='#' onclick='doGoogleLogout()' target='_self' alt='' ></map>";
				document.getElementById("title").innerHTML=mystring;
			} else {
				mystring = "<img src='facemapbanner.gif' usemap='#m_facemapbanner' border=0><map name='m_facemapbanner'><area shape='rect' coords='908,61,995,75' href='#' onclick='doGoogleLogin()' target='_self' alt='' ></map>";
				document.getElementById("title").innerHTML=mystring;
			} 
			loadCalendar(EVENT_FEED_URL);
			///////////////////////////
			var add_to_names="";
			// Create and Center a Map
			var options = {

				showOnLoad : true

			};

			map = new GMap2(document.getElementById("map_canvas"), {googleBarOptions: options});
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(40, -95), 4);
			map.enableGoogleBar();
			// Code to parse the kml file on our own	
			if (window.ActiveXObject) {
				parser=new ActiveXObject("Microsoft.XMLDOM");
				parser.async=false;
				parser.load("/goGreen/kmlFiles/3404940.kml");
			}
			// code for Mozilla, Firefox, Opera, etc.
			else if (document.implementation && document.implementation.createDocument) {
				parser = new XMLHttpRequest();
				parser.open( "GET", "/goGreen/kmlFiles/3404940.kml", false );
				parser.send(null);
		 		parser = parser.responseXML;
  			}
			else {
  				alert('Your browser cannot handle this script');
  			}
			// End kml parse code
			points = parser.getElementsByTagName( "name" );
			coords = parser.getElementsByTagName( "coordinates" );
			descs = parser.getElementsByTagName( "description" ); 
			for (i=0;i<points.length;i++) {
				add_to_names +="<a href = \"#none\" onmouseup= 'zoomOnFriend(\""+i+"\")'>";
				add_to_names +=points.item(i).firstChild.nodeValue+"</a><br>";
				var mycoords = coords.item(i).firstChild.nodeValue.split(",");
				marker=newMarker(new GLatLng(mycoords[1], mycoords[0]),points.item(i).firstChild.nodeValue,descs.item(i).firstChild.nodeValue);
				marker_array.push(marker);
			}
		
			document.getElementById("friend_names").innerHTML=add_to_names;	
			var cluster = new ClusterMarker(map, { markers:marker_array } );
			cluster.fitMapMaxZoom=2;
			cluster.intersectPadding=-1;
			cluster.refresh();
      	}
     }
	
	function showFriends(qualifier) {
		if (qualifier==1) {
			var center = map.getBounds().getSouthWest().lat() + "," + map.getBounds().getSouthWest().lng()+ "   " + map.getBounds().getNorthEast().lat() + "," + map.getBounds().getNorthEast().lng();
          			//document.getElementById("test").innerHTML = center.toString() + " " + points.length;
				i=0;
				add_to_names="";
				while(i<points.length) {
					var mycoords = coords.item(i).firstChild.nodeValue.split(",");
					if(mycoords[1]<map.getBounds().getNorthEast().lat() && mycoords[1]> map.getBounds().getSouthWest().lat() && mycoords[0]<map.getBounds().getNorthEast().lng() && mycoords[0]>map.getBounds().getSouthWest().lng() ) {
						add_to_names +="<a href = \"#none\" onmouseup= 'zoomOnFriend(\""+i+"\")'>";
						add_to_names +=points.item(i).firstChild.nodeValue+"</a><br>";
					}
					document.getElementById("test").innerHTML=mycoords[1]+" "+mycoords[0];
					i++;
				}
				document.getElementById("friend_names").innerHTML=add_to_names;	
		} else {
			i=0;
				add_to_names="";
				while(i<points.length) {
					var mycoords = coords.item(i).firstChild.nodeValue.split(",");
					add_to_names +="<a href = \"#none\" onmouseup= 'zoomOnFriend(\""+i+"\")'>";
					add_to_names +=points.item(i).firstChild.nodeValue+"</a><br>";
					document.getElementById("test").innerHTML=mycoords[1]+" "+mycoords[0];
					i++;
				}
				document.getElementById("friend_names").innerHTML=add_to_names;	
		}

	}
	
	function addMark(marker,name,desc,n) {
		marker_array.push(marker);
	}

	function newMarker(markerLocation, markerId,markerDesc) {
		 var marker=new GMarker(markerLocation, {title:'Marker['+markerId+']'});
		 GEvent.addListener(marker, 'click', function() {
		  marker.openInfoWindowHtml(markerId+'<br>'+markerDesc);
		});
		 return marker;
	}

	function zoomOnFriend(mystring) {
		document.getElementById("test").innerHTML=mystring;
		var mycoords = coords.item(mystring).firstChild.nodeValue.split(",");	
		var point = new GLatLng(mycoords[1], mycoords[0]);
		map.setZoom(15);
		map.setCenter(point);
 		map.openInfoWindow(point, descs.item(mystring).firstChild.nodeValue);


	}
      GSearch.setOnLoadCallback(initialize);
    </script>
<script type="text/javascript" language="JavaScript" src="calendar_integrate.js"></script>
<script type="text/javascript" language="JavaScript" src="integrate.js"></script>
<link href="p24-2008.css" rel="stylesheet" type="text/css">
</head>
<body onunload="GUnload()">
<div id="title"></div>
<div id="outer"> 
  <table id="container">
    <tr valign="top" align="center"> 
      <td> <table width="950" align="center" id="mainTable">
          <tr valign="top"> 
            <td width="700"><div class="mapRegion" id="map_canvas" style="width: 700px; height: 500px"></div></td>
            <td width="250" class="calendarRegion"> 
		<div id="calendarTop"></div>
              <div id="calendarTitle"></div>
              <div id="events"></div>
		<div id="calendarBottom"></div></td>
          </tr>
          <tr> 
            <td colspan="2" class="dataRegion"><a href = "#" onClick='showFriends(1)'>Refresh Friends in Area</a><br>
				     <a href = "#" onClick='showFriends(0)'>Show All Friends</a><br>Your friends:<br> <div id="friend_names"></div></td>
          </tr>
        </table></td>
    </tr>
  </table>
</div>
<div id="footer">&quot;Team Name&quot;: Paul Kamp III, Paul Pham, Connor Imes, 
  & Andrew Emmons <br>
  Released under GPLv3 for the USC Google All Nighter - February 17-18, 2008.</div>
<div id = "test"></div>
</body>
</html>
